package com.yangle.frame.admin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yangle.frame.admin.entity.User;
import com.yangle.frame.admin.mapper.UserMapper;
import com.yangle.frame.admin.service.UserService;
import com.yangle.frame.common.service.RedisServiceImpl;
import com.yangle.frame.common.utils.EhcacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangle on 2018/6/1.
 */
@Controller
public class DemoController {
    @Autowired
    private UserService userService;
    @Autowired
    private EhcacheUtils ehcacheUtils;
    @Autowired
    private RedisServiceImpl redisService;
    @ResponseBody
    @RequestMapping("/test")
    public User test(){

        PageHelper.startPage(0,20);
        List<User> users = userService.getAll();
        PageInfo<User> pageInfo=new PageInfo<>(users);
        long total = pageInfo.getTotal();
        System.out.printf(users.size()+"");
        return userService.getUser();
    }
    @ResponseBody
    @RequestMapping("/add")
    public String add(){
        List<User> users = userService.getAll();
//        redisService.set("users",users);
        ehcacheUtils.update("users",users);
        return "添加成功";
    }
    @ResponseBody
    @RequestMapping("/get")
    public List<User> get(){
//        List<User> users = userService.getAll();
        List<User> users= (List<User>) ehcacheUtils.get("users");
        return users;
    }

}
